<?php
declare(strict_types=1);

namespace App\Controller\v1;

use App\Controller\AbstractController;
use App\Request\Web\RegisterRequest;
use App\Request\Web\UserProfileRequest;
use App\Request\Web\RefreshTokenRequest;
use App\Resource\Web\UserProfileResource;
use App\Service\Web\UsersService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Resource\Json\JsonResource;


#[Controller(prefix: '/api/web/v1')]
class UserController extends AbstractController
{
    #[Inject]
    private UsersService $userService;

    #[PostMapping('refresh_token')]
    public function refresh_token(RefreshTokenRequest $request)
    {
        $data = $request->validated();

        $result = $this->userService->refresh_token($data['refresh_token']);

        return new JsonResource($result);
    }

    #[GetMapping('user_profiles/view')]
    public function user_profiles_view()
    {
        $result = $this->userService->user_profiles_view();
        return new UserProfileResource($result);
    }
    #[PostMapping('user_profiles/update')]
    public function user_profiles_update(UserProfileRequest $request)
    {
        $data = $request->validated();
        $result = $this->userService->user_profiles_update($data);

        return new JsonResource($result);
    }
}